﻿//********************************************************************************//
//创建日期：<创建日期，2010-08-02>
//创建作者：<王一飞，wangyifei@shanghai3h.com>
//功能说明：YS_SF_FAPIAOHMKC实体层次
//********************************************************************************//

#region Entity

using System;
using System.Data;
using Entity;
using Oracle.DataAccess.Client;
using Platform.Configuration;
using Platform.Data;

namespace Entity
{
    [Serializable]
    public class YS_SF_FAPIAOHMKC
    {
        private decimal? m_dec_i_feiyongbh;

        private decimal? m_dec_i_jlzt;

        private decimal? m_dec_i_zhuangtai;

        private decimal m_dec_id;

        private DateTime? m_DT_d_dayinrq;

        private DateTime? m_DT_d_shijian;

        private string m_str_s_beiyong1;

        private string m_str_s_beiyong2;

        private string m_str_s_czy;

        private string m_str_s_haoma;

        private string m_str_s_shoufeifs;

        /// <summary>
        ///     主键
        /// </summary>
        public decimal ID
        {
            get { return m_dec_id; }
            set { m_dec_id = value; }
        }

        /// <summary>
        ///     号码
        /// </summary>
        public string S_HAOMA
        {
            get { return m_str_s_haoma; }
            set { m_str_s_haoma = value; }
        }

        /// <summary>
        ///     费用编号
        /// </summary>
        public decimal? I_FEIYONGBH
        {
            get { return m_dec_i_feiyongbh; }
            set { m_dec_i_feiyongbh = value; }
        }

        /// <summary>
        ///     状态
        /// </summary>
        public decimal? I_ZHUANGTAI
        {
            get { return m_dec_i_zhuangtai; }
            set { m_dec_i_zhuangtai = value; }
        }

        /// <summary>
        ///     收费方式
        /// </summary>
        public string S_SHOUFEIFS
        {
            get { return m_str_s_shoufeifs; }
            set { m_str_s_shoufeifs = value; }
        }

        /// <summary>
        ///     打印日期
        /// </summary>
        public DateTime? D_DAYINRQ
        {
            get { return m_DT_d_dayinrq; }
            set { m_DT_d_dayinrq = value; }
        }

        /// <summary>
        ///     时间
        /// </summary>
        public DateTime? D_SHIJIAN
        {
            get { return m_DT_d_shijian; }
            set { m_DT_d_shijian = value; }
        }

        /// <summary>
        ///     操作员
        /// </summary>
        public string S_CZY
        {
            get { return m_str_s_czy; }
            set { m_str_s_czy = value; }
        }

        /// <summary>
        ///     是否删除
        /// </summary>
        public decimal? I_JLZT
        {
            get { return m_dec_i_jlzt; }
            set { m_dec_i_jlzt = value; }
        }

        /// <summary>
        ///     备用1
        /// </summary>
        public string S_BEIYONG1
        {
            get { return m_str_s_beiyong1; }
            set { m_str_s_beiyong1 = value; }
        }

        /// <summary>
        ///     备用2
        /// </summary>
        public string S_BEIYONG2
        {
            get { return m_str_s_beiyong2; }
            set { m_str_s_beiyong2 = value; }
        }
    }
}

#endregion

#region EntityProcess

namespace BLL.Access
{
    //using System.Data.OracleClient;

    public class YS_SF_FAPIAOHMKCProcess
    {
        #region Field

        protected string conn;

        #endregion

        #region Construction

        public YS_SF_FAPIAOHMKCProcess()
        {
            conn = ConfigHelper.PlatformConnString;
        }

        #endregion

        #region public

        /// <summary>
        ///     根据YS_SF_FAPIAOHMKC实体添加或者修改YS_SF_FAPIAOHMKC信息
        /// </summary>
        public bool InsertOrUpdate(YS_SF_FAPIAOHMKC YS_SF_FAPIAOHMKC, OracleTransaction Transaction)
        {
            if (YS_SF_FAPIAOHMKC.ID == 0)
                InsertYS_SF_FAPIAOHMKC(YS_SF_FAPIAOHMKC, Transaction);
            else
                UpdateYS_SF_FAPIAOHMKC(YS_SF_FAPIAOHMKC, Transaction);
            return YS_SF_FAPIAOHMKC.ID == 0 ? false : true;
        }

        /// <summary>
        ///     根据YS_SF_FAPIAOHMKC实体添加或修改YS_SF_FAPIAOHMKC信息
        /// </summary>
        public bool InsertOrUpdate(YS_SF_FAPIAOHMKC YS_SF_FAPIAOHMKC)
        {
            return InsertOrUpdate(YS_SF_FAPIAOHMKC, null);
        }


        /// <summary>
        ///     根据YS_SF_FAPIAOHMKC主键删除YS_SF_FAPIAOHMKC信息
        /// </summary>
        /// <param name="ID"></param>
        public bool DeleteYS_SF_FAPIAOHMKC(decimal ID, OracleTransaction Transaction)
        {
            var spName = "CS_DelYS_SF_FAPIAOHMKC";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = ID;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        ///     根据YS_SF_FAPIAOHMKC主键删除YS_SF_FAPIAOHMKC信息
        /// </summary>
        /// <param name="ID"></param>
        public bool DeleteYS_SF_FAPIAOHMKC(decimal ID)
        {
            return DeleteYS_SF_FAPIAOHMKC(ID, null);
        }

        /// <summary>
        ///     根据条件删除YS_SF_FAPIAOHMKC信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteYS_SF_FAPIAOHMKCsDynamic(string WhereClause, OracleTransaction Transaction)
        {
            var spName = "CS_DelYS_SF_FAPIAOHMKCsDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = WhereClause;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        ///     根据条件删除YS_SF_FAPIAOHMKC信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteYS_SF_FAPIAOHMKCsDynamic(string WhereClause)
        {
            return DeleteYS_SF_FAPIAOHMKCsDynamic(WhereClause, null);
        }

        /// <summary>
        ///     根据YS_SF_FAPIAOHMKC主键选择YS_SF_FAPIAOHMKC信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>YS_SF_FAPIAOHMKC信息</returns>
        public YS_SF_FAPIAOHMKC SelectYS_SF_FAPIAOHMKC(decimal ID, OracleTransaction Transaction)
        {
            var spName = "CS_SelYS_SF_FAPIAOHMKC";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = ID;
            OracleDataReader rd;
            if (Transaction == null)
                rd = OracleHelper.ExecuteReader(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                rd = OracleHelper.ExecuteReader(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (rd.Read())
            {
                var YS_SF_FAPIAOHMKC = PopulateYS_SF_FAPIAOHMKC(rd);
                rd.Close();
                return YS_SF_FAPIAOHMKC;
            }
            return null;
        }

        /// <summary>
        ///     根据YS_SF_FAPIAOHMKC主键选择YS_SF_FAPIAOHMKC信息
        /// </summary>
        /// <returns>YS_SF_FAPIAOHMKC信息</returns>
        public YS_SF_FAPIAOHMKC SelectYS_SF_FAPIAOHMKC(decimal ID)
        {
            return SelectYS_SF_FAPIAOHMKC(ID, null);
        }

        /// <summary>
        ///     选择所有YS_SF_FAPIAOHMKC信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>所有YS_SF_FAPIAOHMKC信息</returns>
        public DataTable SelectYS_SF_FAPIAOHMKCsAll(OracleTransaction Transaction)
        {
            var spName = "CS_SelYS_SF_FAPIAOHMKCsAll";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }

        /// <summary>
        ///     选择所有YS_SF_FAPIAOHMKC信息
        /// </summary>
        /// <returns>所有YS_SF_FAPIAOHMKC信息</returns>
        public DataTable SelectYS_SF_FAPIAOHMKCsAll()
        {
            return SelectYS_SF_FAPIAOHMKCsAll(null);
        }

        /// <summary>
        ///     根据条件选择YS_SF_FAPIAOHMKC信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>YS_SF_FAPIAOHMKC信息</returns>
        public DataTable SelectYS_SF_FAPIAOHMKCsDynamic(string WhereClause, string OrderByExpression,
            OracleTransaction Transaction)
        {
            var spName = "CS_SelYS_SF_FAPIAOHMKCsDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }


        /// <summary>
        ///     根据条件选择YS_SF_FAPIAOHMKC信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <returns>YS_SF_FAPIAOHMKC信息</returns>
        public DataTable SelectYS_SF_FAPIAOHMKCsDynamic(string WhereClause, string OrderByExpression)
        {
            return SelectYS_SF_FAPIAOHMKCsDynamic(WhereClause, OrderByExpression, null);
        }


        /// <summary>
        ///     根据条件选择YS_SF_FAPIAOHMKC信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>YS_SF_FAPIAOHMKC信息</returns>
        public DataTable SelectYS_SF_FAPIAOHMKCsDynamic(string WhereClause, string OrderByExpression, int PageIndex,
            int PageSize, OracleTransaction Transaction)
        {
            var spName = "CS_SelYS_SF_FAPIAOHMKCsDynPaged";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            storedParams[2].Value = PageIndex;
            storedParams[3].Value = PageSize;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }


        /// <summary>
        ///     根据条件选择YS_SF_FAPIAOHMKC信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <returns>YS_SF_FAPIAOHMKC信息</returns>
        public DataTable SelectYS_SF_FAPIAOHMKCsDynamic(string WhereClause, string OrderByExpression, int PageIndex,
            int PageSize)
        {
            return SelectYS_SF_FAPIAOHMKCsDynamic(WhereClause, OrderByExpression, PageIndex, PageSize, null);
        }

        /// <summary>
        ///     根据条件更新YS_SF_FAPIAOHMKC字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateYS_SF_FAPIAOHMKCsDynamic(string UpdateValue, string WhereClause, OracleTransaction Transaction)
        {
            var result = 0;
            if (UpdateValue == "" || WhereClause == "")
                return 0;
            var spName = "CS_UpdYS_SF_FAPIAOHMKCDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            storedParams[0].Value = UpdateValue;
            storedParams[1].Value = WhereClause;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            result = Convert.ToInt32(storedParams[2].Value);
            return result;
        }

        /// <summary>
        ///     根据条件更新YS_SF_FAPIAOHMKC字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateYS_SF_FAPIAOHMKCsDynamic(string UpdateValue, string WhereClause)
        {
            return UpdateYS_SF_FAPIAOHMKCsDynamic(UpdateValue, WhereClause, null);
        }

        #endregion

        #region Private

        private int InsertYS_SF_FAPIAOHMKC(YS_SF_FAPIAOHMKC YS_SF_FAPIAOHMKC, OracleTransaction Transaction)
        {
            var spName = "CS_InsYS_SF_FAPIAOHMKC";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = YS_SF_FAPIAOHMKC.S_HAOMA;
            storedParams[1].Value = YS_SF_FAPIAOHMKC.I_FEIYONGBH;
            storedParams[2].Value = YS_SF_FAPIAOHMKC.I_ZHUANGTAI;
            storedParams[3].Value = YS_SF_FAPIAOHMKC.S_SHOUFEIFS;
            storedParams[4].Value = YS_SF_FAPIAOHMKC.D_DAYINRQ;
            storedParams[5].Value = YS_SF_FAPIAOHMKC.D_SHIJIAN;
            storedParams[6].Value = YS_SF_FAPIAOHMKC.S_CZY;
            storedParams[7].Value = YS_SF_FAPIAOHMKC.I_JLZT;
            storedParams[8].Value = YS_SF_FAPIAOHMKC.S_BEIYONG1;
            storedParams[9].Value = YS_SF_FAPIAOHMKC.S_BEIYONG2;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            YS_SF_FAPIAOHMKC.ID = Convert.ToInt32(storedParams[10].Value);
            return result;
        }

        private bool UpdateYS_SF_FAPIAOHMKC(YS_SF_FAPIAOHMKC YS_SF_FAPIAOHMKC, OracleTransaction Transaction)
        {
            var spName = "CS_UpdYS_SF_FAPIAOHMKC";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = YS_SF_FAPIAOHMKC.S_HAOMA;
            storedParams[1].Value = YS_SF_FAPIAOHMKC.I_FEIYONGBH;
            storedParams[2].Value = YS_SF_FAPIAOHMKC.I_ZHUANGTAI;
            storedParams[3].Value = YS_SF_FAPIAOHMKC.S_SHOUFEIFS;
            storedParams[4].Value = YS_SF_FAPIAOHMKC.D_DAYINRQ;
            storedParams[5].Value = YS_SF_FAPIAOHMKC.D_SHIJIAN;
            storedParams[6].Value = YS_SF_FAPIAOHMKC.S_CZY;
            storedParams[7].Value = YS_SF_FAPIAOHMKC.I_JLZT;
            storedParams[8].Value = YS_SF_FAPIAOHMKC.S_BEIYONG1;
            storedParams[9].Value = YS_SF_FAPIAOHMKC.S_BEIYONG2;
            storedParams[10].Value = YS_SF_FAPIAOHMKC.ID;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }


        private YS_SF_FAPIAOHMKC PopulateYS_SF_FAPIAOHMKC(IDataReader dr)
        {
            var YS_SF_FAPIAOHMKC = new YS_SF_FAPIAOHMKC();
            YS_SF_FAPIAOHMKC.ID = dr["ID"] == DBNull.Value ? 0 : (decimal) dr["ID"];
            YS_SF_FAPIAOHMKC.S_HAOMA = dr["S_HAOMA"] == DBNull.Value ? null : (string) dr["S_HAOMA"];
            YS_SF_FAPIAOHMKC.I_FEIYONGBH = dr["I_FEIYONGBH"] == DBNull.Value ? null : (decimal?) dr["I_FEIYONGBH"];
            YS_SF_FAPIAOHMKC.I_ZHUANGTAI = dr["I_ZHUANGTAI"] == DBNull.Value ? null : (decimal?) dr["I_ZHUANGTAI"];
            YS_SF_FAPIAOHMKC.S_SHOUFEIFS = dr["S_SHOUFEIFS"] == DBNull.Value ? null : (string) dr["S_SHOUFEIFS"];
            YS_SF_FAPIAOHMKC.D_DAYINRQ = dr["D_DAYINRQ"] == DBNull.Value ? null : (DateTime?) dr["D_DAYINRQ"];
            YS_SF_FAPIAOHMKC.D_SHIJIAN = dr["D_SHIJIAN"] == DBNull.Value ? null : (DateTime?) dr["D_SHIJIAN"];
            YS_SF_FAPIAOHMKC.S_CZY = dr["S_CZY"] == DBNull.Value ? null : (string) dr["S_CZY"];
            YS_SF_FAPIAOHMKC.I_JLZT = dr["I_JLZT"] == DBNull.Value ? null : (decimal?) dr["I_JLZT"];
            YS_SF_FAPIAOHMKC.S_BEIYONG1 = dr["S_BEIYONG1"] == DBNull.Value ? null : (string) dr["S_BEIYONG1"];
            YS_SF_FAPIAOHMKC.S_BEIYONG2 = dr["S_BEIYONG2"] == DBNull.Value ? null : (string) dr["S_BEIYONG2"];
            return YS_SF_FAPIAOHMKC;
        }


        private void AddRowNumber(DataTable dt)
        {
            dt.Columns.Add(new DataColumn("RowNumber", typeof(int)));
            for (var i = 0; i < dt.Rows.Count; i++)
                dt.Rows[i][dt.Columns.Count - 1] = i + 1;
        }

        #endregion
    }
}

#endregion